package god530.com.simpleapp_slide.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

import god530.com.simpleapp_slide.database.bean.DetailBean;

/**
 * Created by Administrator on 2016/12/21.
 */

public class DBDetailsUtils {

    public static final void insert(Context ctx, DetailBean bean) {
        SQLiteDatabase db = DBHelper.getSqliteDatabase(ctx);
        ContentValues values = new ContentValues();
        values.put(DBContants.DETAILS.SUBS, bean.getSubs());
        values.put(DBContants.DETAILS.TYPES, bean.getTypes());
        values.put(DBContants.DETAILS.MONEY, bean.getMoney());
        values.put(DBContants.DETAILS.TIME, bean.getTime());
        db.insert(DBContants.DETAILS.TABLE, null, values);
    }

    public static final void query(Context ctx) {

        Cursor cursor = DBHelper.getSqliteDatabase(ctx).query(true, DBContants.DETAILS.TABLE, null, null, null, null, null, null, null);

    }

    private static List<DetailBean> queryCursor(Cursor cursor) {
        List<DetailBean> listDetails = new ArrayList<>();


        if (cursor.getCount() < 1) return listDetails;
        cursor.moveToFirst();

        int id = cursor.getColumnIndex(DBContants.DETAILS.ID);
        int subs = cursor.getColumnIndex(DBContants.DETAILS.SUBS);
        int types = cursor.getColumnIndex(DBContants.DETAILS.TYPES);
        int money = cursor.getColumnIndex(DBContants.DETAILS.MONEY);
        int time = cursor.getColumnIndex(DBContants.DETAILS.TIME);

        do {
            DetailBean bean = new DetailBean(
                    cursor.getString(subs),
                    cursor.getString(types),
                    cursor.getString(money),
                    cursor.getString(time));
            bean.setId(cursor.getInt(id));
            listDetails.add(bean);
        } while (cursor.moveToNext());

        return listDetails;
    }

}
